package com.controller;

import com.orm.Db;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by lirance on 16/5/25.
 */
public class GetResultList {
    public void insertResultSavedLists(int k, int gNum, double lmd, int clusteNum, double mae, double rmse) throws Exception {
        Db.getInstance().executeUpdate("insert into resultSave(k,gNum,lmd,clusteNum,mae,rmse) value(?,?,?,?,?,?)", k, gNum, lmd, clusteNum, mae, rmse);
    }

    public List<Double> GetResult(int k, int gNum, double lmd, int clusteNum) throws Exception {
        List<Double> result = new ArrayList<>();
        String sql = "select * from resultSave where clusteNum = " + clusteNum + " and lmd = " + lmd + " and gNum = " + gNum + " and k = " + k;
        ResultSet resultSet = Db.getInstance().executeQuery(sql);
        while (resultSet.next() /*&& i <= 1000*/) {
            result.add(Double.parseDouble(resultSet.getString("mae")));
            result.add(Double.parseDouble(resultSet.getString("rmse")));
        }
        resultSet.close();

        return result;
    }


}
